﻿using Domain.Entity;
using DtoFw;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Renci.SshNet.Messages;
using Repository.Base;
using Service;
using System.Collections.Generic;

namespace SceneEvidenceAPI.Controllers
{
    /// <summary>
    /// 榆林市公安局财物系统3D对外第三方接口
        /// </summary>
        [Route("api/v3D")]
    public class ThreedController : BaseController
    {
        private readonly ThreedService _threedService;
        public ThreedController(ThreedService threedService)
        {
            this._threedService = threedService;
        }
        /// <summary>
        /// 1、获取所有仓库，物品数量
        /// </summary>
        /// <param name="organID">单位id</param>
        [AllowAnonymous]
        [HttpGet("GetWarehouse")]
        public string GetWarehouse(long organID)
        {
            var retList = this._threedService.GetWarehouse(organID);
            return Write(new { code = 200, data = retList });
        }
        /// <summary>
        /// 2、获取仓库设备物品数量接口
        /// </summary>
        /// <param name="warehouseID">仓库id</param>
        [AllowAnonymous]
        [HttpGet("GetDevicesByWid")]
        public string GetDevicesByWid(long warehouseID)
        {
            var retList = this._threedService.GetDevicesByWid(warehouseID);
            return Write(new { code = 200, data = retList });
        }
        /// <summary>
        /// 3、获取设备里面的格子信息、物品数量
        /// </summary>
        /// <param name="deviceID">设备id</param>
        [AllowAnonymous]
        [HttpGet("GetDeviceDetail")]
        public string GetDeviceDetail(long deviceID, int col, int direction)
        {
            var retList = this._threedService.GetDeviceDetail(deviceID, col, direction);
            return Write(new { code = 200, data = retList });
        }
        /// <summary>
        /// 4、获取设备格子里面的物品列表接口
        ///    根据格子ID获取物品列表信息接口
        /// </summary>
        /// <param name="cellID">格子id</param>
        [AllowAnonymous]
        [HttpGet("GetDeviceCellWplist")]
        public string GetDeviceCellWplist(long cellID)
        {
            var retList = this._threedService.GetDeviceCellWplist(cellID);
            return Write(new { code = 200, data = retList });
        }
        /// <summary>
        /// 5、获取设备里面的物品列表接口
        ///    根据设备ID获取物品列表信息接口,用于光盘柜
        /// </summary>
        /// <param name="deviceID">设备id</param>
        [AllowAnonymous]
        [HttpGet("GetDeviceWplist")]
        public string GetDeviceWplist(long deviceID)
        {
            var retList = this._threedService.GetDeviceWplist(deviceID);
            return Write(new { code = 200, data = retList });
        }
        /// <summary>
        /// 6、获取单个物品的详细信息
        /// </summary>
        /// <param name="id">物品id</param>
        [AllowAnonymous]
        [HttpGet("GetWpDetailByID")]
        public string GetWpDetailByID(long id)
        {
            var retList = this._threedService.GetWpDetailByID(id);
            return Write(new { code = 200, data = retList });
        }
        /// <summary>
        /// 7、获取温度、湿度接口
        /// </summary>
        /// <param name="organID">单位id</param>
        [AllowAnonymous]
        [HttpGet("GetEnvironments")]
        public string GetEnvironments(long organID)
        {
            var obj = this._threedService.GetEnvironments(organID);
            if(obj == null)
            {
                return Write(new { code = 300, message = "缺少数据" });
            }
            return Write(new { code = 200, data = obj });
        }

        string Write(object json)
        {
            var js = new Newtonsoft.Json.JsonSerializerSettings();
            js.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore;
            js.DateFormatString = "yyyy-MM-dd";
            return Newtonsoft.Json.JsonConvert.SerializeObject(json, js);
        }
    }
}
